package com.gr.staffpm.pages.behaviour;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.html.IHeaderResponse;

public class FocusOnLoadBehavior extends AbstractBehavior {

    private static final long serialVersionUID = 1L;
    private Component component;

    @Override
    public void bind(Component component) {
        this.component = component;
        component.setOutputMarkupId(true);
    }

    @Override
    public void renderHead(IHeaderResponse iHeaderResponse) {
        super.renderHead(iHeaderResponse);
        iHeaderResponse.renderOnLoadJavascript("document.getElementById('" + component.getMarkupId() + "').focus()");
    }

    @Override
    public boolean isTemporary() {
        // remove the behaviour after component has been rendered       
        return true;
    }
}
